using NUnit.Framework;
using ValidationFramework;
using ValidationFramework.Configuration;

namespace ExampleLibraryCSharp.NewRule
{
    [TestFixture]
    public class RequiredCharacterRuleConfigReaderUsage
    {

        public class Person
        {
            public string Name
            {
                get;
                set;
            }
        }



       private const string propertyXmlString = @"<?xml version='1.0' encoding='utf-8' ?>
<validationMapping xmlns='urn:validationFramework-validationDefinition-1.5'>
  <class 
    typeName='ExampleLibraryCSharp.NewRule.RequiredCharacterRuleConfigReaderUsage+Person, ExampleLibraryCSharp'>
    <property name='Name'>
      <rule 
        typeName='ExampleLibraryCSharp.NewRule.RequiredCharacterRuleConfigReader, ExampleLibraryCSharp' requiredCharacter='s'/>
    </property>
  </class>
</validationMapping>";

        [Test]
        public void Run()
        {

            var person = new Person();
            ConfigurationService.AddXmlString(propertyXmlString);
            var propertyValidationManager = new PropertyValidationManager(person);

            propertyValidationManager.Validate("Name");
            // Valid dinosaur.Name is Null
            Assert.IsTrue(propertyValidationManager.IsValid);

            person.Name = "john";
            propertyValidationManager.Validate("Name");
            // Invalid because Name does not contain 's'
            Assert.IsFalse(propertyValidationManager.IsValid);

            person.Name = "simon";
            propertyValidationManager.Validate("Name");
            // Valid because Name does contain 's'
            Assert.IsTrue(propertyValidationManager.IsValid);
        }
    }
}
